import grpc

import greeting_pb2
import greeting_pb2_grpc

def run():
    """ 
    1. 先增加1个channel连接 
    2. 建立1个Stub
    3。调用服务器上的函数接，并获取 response.
    """
    with grpc.insecure_channel('localhost:50051') as channel:    # grpc 通道
        stub = greeting_pb2_grpc.GreeterStub(channel)            # 客户端stub，用于序列化消息和发送请求
        response = stub.greet(
            greeting_pb2.ClientInput(name='小王', greeting="你好"))
    print("Greeter client received following from server: " + response.message)
    
if __name__ == "__main__":
    run()


